<?php
class RobFlowerGrowersInfoVo extends SzAbstractMySqlVo
{

    private $userId;
    private $position;
    private $targetId;
    private $coolingTime;
    private $reward;

    /**
     * Initialize RobFlowerGrowersInfoVo.
     *
     * @param $userId
     * @param $position
     * @param $targetId
     * @param $coolingTime
     * @param $reward
     * @param boolean $isInsert default false, means for now this vo is initialized not for insert process
     * @return RobFlowerGrowersInfoVo
     */
    public function __construct($userId, $position, $targetId, $coolingTime, $reward, $isInsert = false) {
        $this->userId = $userId;
        $this->position = $position;
        $this->targetId = $targetId;
        $this->coolingTime = $coolingTime;
        $this->reward = is_string($reward) ? json_decode($reward, true) : (array)$reward;

        $this->isInsert = $isInsert;
        $this->voClassName = 'RobFlowerGrowersInfoVo';
        $this->ormName = 'RobFlowerGrowersInfo';
    }

    /**
     * @see SzAbstractVo::toArray
     */
    public function toArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'position' => $this->getPosition(),
            'targetId' => $this->getTargetId(),
            'coolingTime' => $this->getCoolingTime(),
            'reward' => ($needEncode) ? $this->getReward() : $this->getRawReward(),
        );
    }

    /**
     * @see SzAbstractVo::toEntireArray
     */
    public function toEntireArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'position' => $this->getPosition(),
            'targetId' => $this->getTargetId(),
            'coolingTime' => $this->getCoolingTime(),
            'reward' => ($needEncode) ? $this->getReward() : $this->getRawReward(),
        );
    }

    /**
     * @see SzAbstractVo::toPureArray
     */
    public function toPureArray()
    {
        return array(
            $this->getUserId(),
            $this->getPosition(),
            $this->getTargetId(),
            $this->getCoolingTime(),
            $this->getReward(),
        );
    }

    public function getUserId()
    {
        return $this->userId;
    }

    public function setUserId($val)
    {
        $this->saveColumnStatus(0, $this->userId);
        $this->userId = $val;
    }

    public function getPosition()
    {
        return $this->position;
    }

    public function setPosition($val)
    {
        $this->saveColumnStatus(1, $this->position);
        $this->position = $val;
    }

    public function getTargetId()
    {
        return $this->targetId;
    }

    public function setTargetId($val)
    {
        $this->saveColumnStatus(2, $this->targetId);
        $this->targetId = $val;
    }

    public function getCoolingTime()
    {
        return $this->coolingTime;
    }

    public function setCoolingTime($val)
    {
        $this->saveColumnStatus(3, $this->coolingTime);
        $this->coolingTime = $val;
    }

    public function getReward()
    {
        return json_encode($this->reward);
    }

    public function getRawReward()
    {
        return $this->reward;
    }

    public function setReward($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 51200) {
            SzLogger::get()->error('[RobFlowerGrowersInfoVo] The length of column reward exceed the limit, length / limit: ' . $encodedLength . ' / 51200');
            throw new SzException(10522, array('RobFlowerGrowersInfoVo', '51200', $encodedLength));
        } else if ($encodedLength > 46080) {
            SzLogger::get()->warn('[RobFlowerGrowersInfoVo] The length of column reward exceed the warning level, length / limit: ' . $encodedLength . ' / 51200');
        }
        $this->saveColumnStatus(4, $this->reward);
        $this->reward = $val;
    }

}
